package com.giteelou.gitee.sdjl01.repo;

import com.giteelou.gitee.sdjl01.entity.City;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface CityRepository extends JpaRepository<City, Long>, JpaSpecificationExecutor<City> {

    City findFirst1ByName(String name);

    Page<City> findByNameLike(String prefixName, Pageable pageable);

    @Query("select c from City c where c.id=?1")
    Optional<City> selectById(Long id);

    @Modifying
    @Query("update City u set u.name = ?1, u.province = ?2 where id=?3")
    int setFixedNameAndProvinceById(String name, String province, @Param("id") Long id);

}